package cn.openea.perpartner.msg.config;

import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @Name: 获取微信公众号基本配置信息
 * @author: Mr.Yun
 * @Created: 2022/11/07 20:56
 */
@Configuration
public class WxMpConfig {

    @Value("${wxmp.appid}")
    String appid;

    @Value("${wxmp.secret}")
    String secret;

    @Value("${wxmp.token}")
    String token;

    @Value("${wxmp.aesKey}")
    String aesKey;

    @Bean
    public WxMpInMemoryConfigStorage getWxMpInMemoryConfigStorage() {
        WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage();
        // 设置微信公众号的开发者ID(AppID)
        config.setAppId(appid);
        // 设置微信公众号的开发者密码(AppSecret)
        config.setSecret(secret);
        // 设置微信公众号的令牌(Token)
        config.setToken(token);
        // 设置微信公众号的消息加解密密钥(EncodingAESKey)
        config.setAesKey(aesKey);
        return config;
    }

    @Bean
    public WxMpService getWxMpService(WxMpInMemoryConfigStorage config) {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(config);
        return wxMpService;
    }

}
